<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .center{
            text-align: center;
        }
    </style>
</head>
<body>
<!--{{include './header.html'}}-->

<h1 style="text-align: center;color: brown">注册</h1>
<div style="width: 500px;margin: 0 auto;margin-top: 200px; ">
    <label>账号</label>&nbsp;&nbsp;<input  style="width: 400px;height: 30px" placeholder="登录" id="d">
    <div style="height: 50px"></div>
    <label>密码</label>&nbsp;&nbsp;<input  style="width: 400px;height: 30px" placeholder="密码" id="m"><br>
    <div style="height: 50px"></div>
    <label>邮箱</label>&nbsp;&nbsp;<input  style="width: 400px;height: 30px" placeholder="邮箱" id="y"><br>
    <a href="/login" style="color:green;font-size: 20px;margin-top: 50px;display: block">跳转到登录</a>

    <a id="re" style="color:green;font-size: 20px;margin-top: 50px;display: block;cursor: pointer;">注册</a>
</div>
<script type="text/javascript" src="/node_modules/jquery/dist/jquery.js"></script>
<script>
        var d=document.getElementById("d")
        var m=document.getElementById("m")
        var y=document.getElementById("y")
        var re=document.getElementById("re")



           re.onclick=function () {

               name=d.value
               password=m.value
               email=y.value
               var hc={
                   email:email,
                   name:name,
                   password:password
               }

               $.ajax({
                   type: "POST",
                   url: "/register",
                   data: hc,
                   dataType:"json",
                   success: function(data){

                    if(data.code_err==1){

                        console.log(data.token)
                        var token =JSON.stringify(data.token)
                        localStorage.setItem('token',token)
                           window.location.href="/";
                       }

                       if(data.code_err==0){
                           alert('邮箱或者账号已经存在');
                       }

                   },
                   error:function (err) {
                      alert('服务器报错'+err.responseJSON.message)

                   }
               });
           }


</script>
</body>
</html>